<template>
	<view class="">
		<NavSearch :weather='weather' :isCity='true' @confirm='confirm' :locaAddress='mixinDistrict'
			@handleSearch='handleSearch' v-model='value'></NavSearch>
		<Swiper @clickSwiper='clickSwiper' :list='swiperList'></Swiper>
		<u-notice-bar bg-color='#FFEAEE' color='#FF0E3D' mode="horizontal" :list="noticeList"></u-notice-bar>
		<ScrollMenu></ScrollMenu>
		<MenuImgs></MenuImgs>
		<GoodsList :list='list'></GoodsList>
		<u-loadmore :status="status" />
	</view>
</template>

<script>
	import NavSearch from './components/NavSearch.vue'
	import Swiper from '@/components/ZY-Swiper/ZY-Swiper.vue'
	import MenuImgs from './components/MenuImgs.vue'
	import ScrollMenu from '@/components/ZY-ScrollMenu/ZY-ScrollMenu.vue'
	import GoodsList from './components/GoodsList.vue'
	import initData from '@/mixin/initData.js'
	import getLocationInfo from '@/mixin/getLocationInfo.js'

	export default {
		components: {
			Swiper,
			NavSearch,
			MenuImgs,
			ScrollMenu,
			GoodsList
		},
		mixins: [initData, getLocationInfo],
		data() {
			return {
				areaName: '',
				value: '',
				swiperList: [],
				list: [],
				locaAddress: '',
				noticeList: ['欢迎光临'] //不给默认值会一个奇怪的错误[ERROR] : Error: Not Found：Page[1][-1,3,2]
			};
		},


		onShow() {
			this.toReset() //清空参数,不然返回到当前页面key会重复
			// 轮播图
			this.getCarouselMapList()


			this.getSysNotice()
			this.getLocationInfo().then(res => {
				this.mixinDistrict = res.address.district
				this.areaName = res.pcd
				this.miXinInit()
			}).catch(err => {
				this.mixinDistrict = ''
				this.areaName = ''
				this.miXinInit()
			})
		},
		computed: {},
		onReady() {
			// this.$refs.uForm.setRules(this.rules);
		},
		onLoad() {

		},
		methods: {
			clickSwiper(i) {

				if (this.swiperList[i].linkType == 1) {
					plus.runtime.openURL(this.swiperList[i].linkUrl)
				} else{
					uni.navigateTo({
						url: '/pages/shopDetail/shopDetail?id=' + this.swiperList[i].linkUrl
					})
				}
			},
			confirm(val, val2) {
				this.areaName = val2
				this.latitude = ''
				this.longitude = ''
				// getApp().globalData.district = val
				this.mixinDistrict = val
				this.toReset()
				this.miXinInit()
			},
			getSysNotice() {
				this.$u.api.getSysNotice().then(res => {
					console.log(res.content, '公告')
					this.noticeList = [res.content]

				})
			},
			handleSearch() {
				uni.navigateTo({
					url: '/pages/search/search?val=' + this.value
				})
			},
			// 请求前的参数处理
			beforeInit() {
				this.apiUrl = "carouselMap/getGoodGoodsList";
				let params = {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					areaName: this.areaName,
					lat: this.latitude,
					lng: this.longitude
				};

				this.params = {
					...params
				};
			},
			// 全部精选
			getGoodGoodsList() {
				this.$u.api.getGoodGoodsList({
					pageNum: 1,
					pageSize: 10
				}).then(res => {
					console.log(res, '全部精选')
					this.goodGoodsList = res
				})
			},
			// 轮播图
			getCarouselMapList() {
				this.$u.api.getCarouselMapList().then(res => {
					this.swiperList = res.map(item => {
						return {
							...item,
							image: item.imgUrl
						}
					})
					console.log(this.swiperList)

				})
			}
		}
	}
</script>

<style lang="scss" scoped>


</style>
